package com.ea.common.result;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result<T> {
    private boolean success;
    private int code;
    private String msg;
    private T data;

    /**
     * 返回一个正确的Result<T>
     * @param data
     * @param <T>
     * @return
     */
    public static <T> Result<T> success(T data) {
        return new Result<>(true, 200, "成功！", data);
    }

    /**
     * 返回一个错误的Result<T>
     * @param code 错误码
     * @param msg 错误描述信息
     * @param <T>
     * @return
     */
    public static <T> Result<T> fail(int code, String msg) {
        return new Result<>(false, code, msg,null);
    }
}
